//
//  UITableViewController+HDChangeDaRenHao.m
//  app
//
//  Created by D on 15/4/14.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDChangeDaRenHao.h"
#import "HDUserInforHttpRequestManger.h"

@implementation HDChangeDaRenHao

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改达人号";
    self.changeDRH.text = [[NSUserDefaults standardUserDefaults]objectForKey:@"uniqueID"];
    UIBarButtonItem * rightBtn = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStyleBordered target:self action:@selector(save:)];
    self.navigationItem.rightBarButtonItem = rightBtn;
    
    self.result_DRH = [JKRemoteResult target:self action:@selector(changeDarenhao:)];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)save:(UIButton*)sender
{
    [self.changeDRH resignFirstResponder];
    
    self.progress_ = [[MBProgressHUD alloc]initWithView:self.view];
    [self.view addSubview:self.progress_];
    [self.view bringSubviewToFront:self.progress_];
    self.progress_.delegate = self;
    [self.progress_ show:YES];

    
    HDUserInforHttpRequestManger * httpManager = [HDUserInforHttpRequestManger shareUserInforHttpRequestManger];
    NSDictionary * params = @{@"identity":self.changeDRH.text};
    [httpManager changeUserInfoWithParams:params reuslt:self.result_DRH];
    
}
-(void)changeDarenhao:(JKRemoteResult*)rt
{
    if (self.progress_) {
        [self.progress_ removeFromSuperview];
        self.progress_ = nil;
    }
    
    if (rt.failure) {
        UIAlertView * av = [[UIAlertView alloc]initWithTitle:nil message:@"请检查网络" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [self.view addSubview:av];
        [av show];
        
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:self.changeDRH.text forKey:@"uniqueID"];
    [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"haveuniqueID"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [alertView removeFromSuperview];
}

@end
